#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
    const char *dev_name = "/dev/key";
	int fd = open(dev_name, O_RDWR);
    if(fd < 0)
        printf("Open the device:[%s] failed\n", dev_name);
    do
    {
        unsigned char key_val;
        read(fd, &key_val, 1);
        if(key_val & 0x80) //松开
            printf("The key[%u] is released\n", key_val & 0x0f);
        else    //按下
            printf("The key[%u] is pressed\n", key_val & 0x0f);
    }while(1);
	close(fd);
	return 0;
}
